package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/10.
 */
@HttpInlet(Conn.ACTIVITY_SUBSCRIBE_TIME)
public class LatestOrderTimeGet extends BaseAsyGet<LatestOrderTimeGet.LatestOrderDateEntity> {

    public String id, time;

    public LatestOrderTimeGet(AsyCallBack<LatestOrderDateEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected LatestOrderDateEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            LatestOrderDateEntity latestOrderDateEntity = new LatestOrderDateEntity();

            JSONArray array = object.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject entityObject = array.optJSONObject(i);

                OrderDateEntity orderDateEntity = new OrderDateEntity();

                orderDateEntity.id = entityObject.optString("id");
                orderDateEntity.time_tip = entityObject.optString("time_tip");
                orderDateEntity.starttime = entityObject.optString("starttime");
                orderDateEntity.endtime = entityObject.optString("endtime");
                orderDateEntity.p_id = entityObject.optString("p_id");
                orderDateEntity.stock = entityObject.optString("stock");

                latestOrderDateEntity.orderDateEntityList.add(orderDateEntity);

            }

           return latestOrderDateEntity;

        }

        return null;
    }

    public static class LatestOrderDateEntity {

        public List<OrderDateEntity> orderDateEntityList = new ArrayList<>();

    }

    public static class OrderDateEntity {

        public String id, p_id, stock, time_tip, starttime, endtime;
    }

    /*
    * {
    "code": 200,
    "data": [
        {
            "id": 1,  //时间ID
            "time_tip": "上午",
            "starttime": "10:00",
            "endtime": "11:30"
        },
        {
            "id": 2,
            "time_tip": "中午",
            "starttime": "12:00",
            "endtime": "13:00"
        },
        {
            "id": 3,
            "time_tip": "下午",
            "starttime": "15:00",
            "endtime": "16:00"
        }
    ]
}*/
}
